package c05;

import org.lwjgl.opengl.GL11;

public class Cube {
    
 // Cube data from example 2-16
    private static final float[][] vertices = {
        {0, 0, 0}, // left bottom front
        {1, 0, 0},  // right bottom front
        {1, 1, 0},   // right top front
        {0, 1, 0},  // left top front
        
        {0, 0, 1}, // left bottom back
        {1, 0, 1},  // right bottom back
        {1, 1, 1},   // right bottom back
        {0, 1, 1}   // left top back
    };
    
    private static final float[][] normals = {
        {0, 0, -1}, 
        {0, 0, 11},
        {0, 1, 0},
        {0, -1, 0},
        {1, 0, 0},
        {-1, 0, 0}
    };
    
    private static final byte[][] indices = {
        {0, 3, 2, 1},
        {4, 5, 6, 7},
        {0, 1, 5, 4},
        {3, 7, 6, 2},
        {0, 4, 7, 3},
        {1, 2, 6, 5}
    };
    
    private static final float[][] colors = {
        {1, 0, 0},
        {0, 1, 0},
        {0, 0, 1},
        {1, 1, 0},
        {0, 1, 1},
        {1, 0, 1}
    };
    

	public static void wireCube(final float size) {
		// Draw all six sides of the cube.
		for (int i = 0; i <indices.length; i++) {
			GL11.glBegin(GL11.GL_LINE_LOOP);
			// Draw all four vertices of the current side.
			for (int m = 0; m < 4; m++) {
				GL11.glColor3f(colors[i][0],colors[i][1],colors[i][2]);
				GL11.glNormal3f(normals[i][0], normals[i][1], normals[i][2]);
				

				
				float[] temp = vertices[indices[i][m]];
				GL11.glVertex3f(temp[0] * size, temp[1] * size, temp[2] * size);
			}
			GL11.glEnd();
		}
	}

	public static void solidCube(final float size) {
		// Draw all six sides of the cube.
		for (int i = 0; i < indices.length; i++) {
			GL11.glBegin(GL11.GL_QUADS);
			GL11.glColor3f(colors[i][0],colors[i][1],colors[i][2]);
			GL11.glNormal3f(normals[i][0], normals[i][1], normals[i][2]);

			// Draw all four vertices of the current side.
			for (int m = 0; m < 4; m++) {
				float[] temp = vertices[indices[i][m]];
				GL11.glNormal3f(normals[i][0], normals[i][1], normals[i][2]);
				GL11.glVertex3f(temp[0] * size, temp[1] * size, temp[2] * size);
			}
			GL11.glEnd();
		}
	}

}
